import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path:"/", //@  就表示当前的 src目录
    redirect:"/login"
  },
  {
    path:"/login",
    component:()=>import("@/views/login/Login")
  },
  {
    path:"/home",
    component:()=>import("@/views/home/Home"),
    redirect:"/welcome",
    children:[
      {
        path:"/welcome",
        component:()=>import("@/views/welcome/Welcome")
      },
      {
        path:"/potentialClients",
        component:()=>import("@/views/potentialClients/PotentialClients")
      },
      {
        path:"/addCustomer",
        component:()=>import("@/views/addCustomer/AddCustomer")
      },
      {
        path:"/dataAnalysis",
        component:()=>import("@/views/dataAnalysis/DataAnalysis")
      }
    ]
  }
]
 

const router = new VueRouter({
  routes
})


router.beforeEach((to,from,next)=>{
  if(to.path != "/login"){
    if(window.sessionStorage.getItem('vuex')){
      next()
    }else{
      next({
        path:"/login"
      })
    }
  }else{
    next()
  } 
})

export default router
